package com.zhaokuner.echo;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import org.apache.commons.io.IOUtils;

public class EchoClient {
	public static void main(String[] args) throws UnknownHostException, IOException {
		String data = "这个要大于5个字这个要大于5个字这个要大于5个字这个要大于5个字这个要大于5个字这个要大于5个字";
		try {
			Socket s = new Socket("127.0.0.1", 8000);

			InputStream dis = s.getInputStream();
			OutputStream dos = s.getOutputStream();
			dos.write(data.getBytes());
			System.out.println("***客户端发送：" + data + " " + data.getBytes().length);
			System.out.println(dis.available());
			String str = IOUtils.toString(dis);
			System.out.println("***服务端返回：" + str);

			dis.close();
			dos.close();
			s.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("***服务失败！***");
			System.exit(0);
		}
	}
}
